package cn.xfdzx.android.apps.shop.presenter;

import cn.xfdzx.android.apps.shop.base.BasePresenter;
import cn.xfdzx.android.apps.shop.bean.AddAddressBeen;
import cn.xfdzx.android.apps.shop.bean.OrderWuliuDaMaBeen;
import cn.xfdzx.android.apps.shop.bean.OrderWuliuShunFengBeen;
import cn.xfdzx.android.apps.shop.contract.AddAddressContract;
import cn.xfdzx.android.apps.shop.contract.XFdOrderWuliuContract;
import cn.xfdzx.android.apps.shop.model.AddAddressModel;
import cn.xfdzx.android.apps.shop.model.XFdOrderWuliuModel;
import cn.xfdzx.android.apps.shop.net.RxScheduler;
import io.reactivex.functions.Consumer;

/**
 * @author azheng
 * @date 2018/6/4.
 * Description：
 */
public class XFdOrderWuliuPresenter extends BasePresenter<XFdOrderWuliuContract.View> implements XFdOrderWuliuContract.Presenter {

    private XFdOrderWuliuContract.Model model;

    public XFdOrderWuliuPresenter() {
        model = new XFdOrderWuliuModel();
    }


    @Override
    public void orderWuliuDama(String orderId) {
        //View是否绑定 如果没有绑定，就不执行网络请求
        if (!isViewAttached()) {
            return;
        }
        mView.showLoading();
        model.orderWuliuDama(orderId)
                .compose(RxScheduler.<OrderWuliuDaMaBeen>Flo_io_main())
                .as(mView.<OrderWuliuDaMaBeen>bindAutoDispose())
                .subscribe(new Consumer<OrderWuliuDaMaBeen>() {
                    @Override
                    public void accept(OrderWuliuDaMaBeen bean) throws Exception {
                        mView.onOrderWuliuDamaSuccess(bean);
                        mView.hideLoading();
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        mView.onError(throwable);
                        mView.hideLoading();
                    }
                });
    }

    @Override
    public void orderWuliuFeng(String orderId) {
        //View是否绑定 如果没有绑定，就不执行网络请求
        if (!isViewAttached()) {
            return;
        }
        mView.showLoading();
        model.orderWuliuFeng(orderId)
                .compose(RxScheduler.<OrderWuliuShunFengBeen>Flo_io_main())
                .as(mView.<OrderWuliuShunFengBeen>bindAutoDispose())
                .subscribe(new Consumer<OrderWuliuShunFengBeen>() {
                    @Override
                    public void accept(OrderWuliuShunFengBeen bean) throws Exception {
                        mView.onOrderWuliuFengSuccess(bean);
                        mView.hideLoading();
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        mView.onError(throwable);
                        mView.hideLoading();
                    }
                });
    }
}
